﻿$.extend(validatePrompt, {
	email : {
		onFocus : "请输入常用的邮箱，将用来找回密码、接收订单信息等",
		succeed : "",
		isNull : "请输入邮箱",
		error : {
			beUsed : "该邮箱已被使用，请更换其它邮箱",
			badFormat : "请输入有效的邮箱地址",
			badLength : "您填写的邮箱过长，邮箱地址只能在50个字符以内"
		}
	},
	password : {
		onFocus : "6-20位字符，可使用字母、数字或符号的组合",
		succeed : "",
		isNull : "请输入密码",
		error : {
			badLength : "密码长度只能在6-20位字符之间",
			badFormat : "密码只能由英文、数字及标点符号组成",
			simplePwd : "密码太弱，有被盗风险，建议设置多种字符组成的复杂密码"
		}
	},
	confirmPassword : {
		onFocus : "请再次输入密码",
		succeed : "",
		isNull : "请输入密码",
		error : {
			badLength : "密码长度只能在6-20位字符之间",
			badFormat2 : "两次输入密码不一致",
			badFormat1 : "密码只能由英文、数字及标点符号组成"
		}
	},
	name : {
		onFocus : "2-20位字符，可由中文或英文组成",
		succeed : "",
		isNull : "请输入联系人姓名",
		error : {
			badLength : "联系人姓名长度只能在2-20位字符之间",
			badFormat : "联系人姓名只能由中文或英文组成"
		}
	},
	phone : {
		onFocus : "请填写联系人常用的电话，以便于我们联系，如：0527-88105500",
		succeed : "",
		isNull : "请输入联系人固定电话",
		error : "电话格式错误，请重新输入"
	},
	mobile : {
		onFocus : "输入联系人手机号",
		succeed : "",
		isNull : "输入联系人手机号",
		error : "手机号格式错误，请重新输入"
	},
	qq : {
		onFocus : "请填写联系人常用的QQ，以便于我们联系，如：888888",
		succeed : "",
		isNull : "请输入联系人常用的QQ",
		error : "QQ格式错误，请重新输入"
	}
});

$
		.extend(
				validateFunction,
				{

					email : function(option) {
						var format = validateRules.isEmail(option.value);
						var format2 = validateRules.betweenLength(option.value,
								0, 50);
						if (!format) {
							validateSettings.error.run(option,
									option.prompts.error.badFormat);
						} else {
							if (!format2) {
								validateSettings.error.run(option,
										option.prompts.error.badLength);
							} else {
								if (!emailstate || emailold != option.value) {
									if (emailold != option.value) {
										emailold = option.value;
										option.errorEle
												.html("<span style='color:#999'>检验中……</span>");
										$
												.getJSON(
														"checkUserName.action?email="
																+ option.value,
														function(date) {
															if (date == 0) {
																if ($("#email_linker")) {
																	$(
																			"#email_linker")
																			.text(
																					option.value);
																}

																validateSettings.succeed
																		.run(option);
																emailstate = true;
															} else {
																validateSettings.error
																		.run(
																				option,
																				option.prompts.error.beUsed);
																emailstate = false;
															}
														})
									} else {
										validateSettings.error.run(option,
												option.prompts.error.beUsed);
										emailstate = false;
									}
								} else {
									if ($("#email_linker")) {
										$("#email_linker").text(option.value);
									}
									validateSettings.succeed.run(option);
								}
							}
						}
					},
					password : function(option) {

						var str1 = option.value;
						var str2 = $("#confirmPassword").val();
						var format = validateRules.isPwd(option.value);
						var length = validateRules.betweenLength(option.value,
								6, 20);
						$("#pwdstrength").hide();
						if (!length && format) {
							validateSettings.error.run(option,
									option.prompts.error.badLength);
						} else if (!length && !format) {
							validateSettings.error.run(option,
									option.prompts.error.badFormat);
						} else if (length && !format) {
							validateSettings.error.run(option,
									option.prompts.error.badFormat);
							/*
							 * } else if (validateRules.simplePwd(str1)) {
							 * validateSettings.error.run(option,
							 * option.prompts.error.simplePwd);
							 */
						} else {
							validateSettings.succeed.run(option);
							validateFunction.pwdstrength();
						}
						if (str2 == str1) {
							$("#confirmPassword").focus();
						}
					},
					confirmPassword : function(option) {
						var str1 = option.value;
						var str2 = $("#password").val();
						var length = validateRules.betweenLength(option.value,
								6, 20);
						var format2 = validateRules.isPwd2(str1, str2);
						var format1 = validateRules.isPwd(str1);
						if (!length) {
							validateSettings.error.run(option,
									option.prompts.error.badLength);
						} else {
							if (!format1) {
								validateSettings.error.run(option,
										option.prompts.error.badFormat1);
							} else {
								if (!format2) {
									validateSettings.error.run(option,
											option.prompts.error.badFormat2);
								} else {
									validateSettings.succeed.run(option);
								}
							}
						}
					},
					name : function(option) {
						var length = validateRules.betweenLength(option.value
								.replace(/[^\x00-\xff]/g, "**"), 2, 20);
						var format = validateRules.isRealName(option.value);
						if (!length) {
							validateSettings.error.run(option,
									option.prompts.error.badLength);
						} else {
							if (!format) {
								validateSettings.error.run(option,
										option.prompts.error.badFormat);
							} else {
								validateSettings.succeed.run(option);
							}
						}
					},
					phone : function(option) {
						var format = validateRules.isTel(option.value);
						if (!format) {
							validateSettings.error.run(option,
									option.prompts.error);
						} else {
							validateSettings.succeed.run(option);
						}
					},
					mobile : function(option) {
						var format = validateRules.isMobile(option.value);
						if (!format) {
							validateSettings.error.run(option,
									option.prompts.error);
						} else {
							validateSettings.succeed.run(option);
						}
					},
					qq : function(option) {
						var length = validateRules.betweenLength(option.value
								.replace(/[^\x00-\xff]/g, "**"), 2, 20);
						var format = validateRules.isNum1(option.value);
						if (!length) {
							validateSettings.error.run(option,
									option.prompts.error.badLength);
						} else {
							if (!format) {
								validateSettings.error.run(option,
										option.prompts.error.badFormat);
							} else {
								validateSettings.succeed.run(option);
							}
						}
					},
					registIndUserInfo_validate : function() {

						$("#email").jdValidate(validatePrompt.email,
								validateFunction.email, true);
						$("#password").jdValidate(validatePrompt.password,
								validateFunction.password, true)
						$("#confirmPassword").jdValidate(
								validatePrompt.confirmPassword,
								validateFunction.confirmPassword, true);
						$("#name").jdValidate(validatePrompt.name,
								validateFunction.name, true);
						$("#phone").jdValidate(validatePrompt.phone,
								validateFunction.phone, true);
						$("#mobile").jdValidate(validatePrompt.mobile,
								validateFunction.mobile, true);
						$("#qq").jdValidate(validatePrompt.qq,
								validateFunction.qq, true);

						return validateFunction.FORM_submit([ "#email",
								"#password", "#confirmPassword", "#name",
								"#phone", "#mobile", "#qq" ]);
					},

					updateIndUserInfo_validate : function() {

						$("#name").jdValidate(validatePrompt.name,
								validateFunction.name, true);
						$("#phone").jdValidate(validatePrompt.phone,
								validateFunction.phone, true);
						$("#mobile").jdValidate(validatePrompt.mobile,
								validateFunction.mobile, true);
						$("#qq").jdValidate(validatePrompt.qq,
								validateFunction.qq, true);

						return validateFunction.FORM_submit([ "#name",
								"#phone", "#mobile", "#qq" ]);
					}
				});

$("#email").jdValidate(validatePrompt.email, validateFunction.email);
$("#password").bind("keyup", function() {
	validateFunction.pwdstrength();
}).jdValidate(validatePrompt.password, validateFunction.password)
$("#confirmPassword").jdValidate(validatePrompt.confirmPassword,
		validateFunction.confirmPassword);
$("#name").jdValidate(validatePrompt.name, validateFunction.name);
$("#mobile").jdValidate(validatePrompt.mobile, validateFunction.mobile);
$("#phone").jdValidate(validatePrompt.phone, validateFunction.phone);
$("#qq").jdValidate(validatePrompt.qq, validateFunction.qq);

$("#registsubmit").click(function() {
	var flag = validateFunction.registIndUserInfo_validate();
	if (flag) {
		$("#registIndUser").submit();
	}
})

$("#updateSubmit").click(function() {
	
	var flag = validateFunction.updateIndUserInfo_validate();
	if (flag) {
		$("#updateIndUserInfo").submit();
	}
})